(function() {
    angular.module('BlurAdmin.pages.redAdminM')
        .controller('WinningRecordCtrl', WinningRecordCtrl);

    function WinningRecordCtrl($scope, $address, $ShareData, $http, $myconfig) {

        var news_id = $ShareData.getRed();; //获取上传过来的id，如果为空则是新增
        console.log(news_id);


        $scope.search_opt = {
            "redpacket_id": news_id,
            "limit": 5,
            "page": "1",
            "user_name": "",
            "mobile": "",
            "area": "",
            "sex": "all" //1女 2男
        };

        var opt = {};
        //分页
        // $scope.bigTotalItems = 50;
        $scope.pageChanged = function(val) {
            var Page_num = val //选中的页面数
            var op = JSON.stringify($scope.search_opt);
            opt = JSON.parse(op);
            opt.sex == 'all' && (delete opt.sex);
            $scope.search_opt.page = val;
            Search_list();
        };

        $scope.Search = function() { //点击搜索
            var op = JSON.stringify($scope.search_opt);
            opt = JSON.parse(op);
            opt.sex == 'all' && (delete opt.sex);
            $http.get($myconfig.api.redpacket_totle_count, { params: opt }).then(function(res) {
                $scope.bigTotalItems = res.data.data;
                Search_list();
            })
        };


        $scope.Qiniu_url = $myconfig.api.Qiniu_url;
        function Search_list() { //获取用户数据
            $http.get($myconfig.api.redpacket_totle_list, { params: opt }).then(function(res) {
                if (res.data.success) {
                    /*for (var i = 0; i < res.data.data.length; i++) { //添加条数属性
                        if (res.data.data[i].headimgurl) {
                            res.data.data[i].headimgurl = res.data.data[i].headimgurl.length > 3 ? ($myconfig.api.Qiniu_url + res.data.data[i].headimgurl) : (res.data.data[i].wxheadimgurl ? res.data.data[i].wxheadimgurl : o);
                        } else {
                            res.data.data[i].headimgurl = res.data.data[i].wxheadimgurl ? res.data.data[i].wxheadimgurl : o;
                        }
                        res.data.data[i].index = (($scope.search_opt.page - 1) * $scope.search_opt.limit) + i + 1;
                    }*/
                    $scope.list_data = res.data.data;
                }
            })
        }

        $scope.Search();


    }
})();